// 游戏状态枚举
export enum GameStatus {
    WAITING = 'waiting',      // 等待开始
    PLAYING = 'playing',      // 进行中
    PAUSED = 'paused',        // 暂停
    FINISHED = 'finished'     // 已结束
}

// 事件类型枚举
export enum EventType {
    PLAYER_JOIN = 'player_join',
    PLAYER_LEAVE = 'player_leave',
    GAME_START = 'game_start',
    GAME_END = 'game_end',
    DATA_CHANGE = 'data_change',
    ACTION_EXECUTE = 'action_execute',
    PART_CHANGE = 'part_change'
}

// 权限枚举
export enum Permission {
    READ_DATA = 'read_data',
    WRITE_DATA = 'write_data',
    MANAGE_PLAYERS = 'manage_players',
    CONTROL_GAME = 'control_game',
    VIEW_LOGS = 'view_logs'
}

// 玩家接口
export interface IPlayer {
    playerId: string;
    roleId: string;
    name?: string;
    permissions: Permission[];
    isOnline: boolean;
    joinedAt: number;
}

// DM接口
export interface IDM {
    dmId: string;
    name?: string;
    permissions: Permission[];
    isOnline: boolean;
}

// 游戏事件接口
export interface IGameEvent {
    eventId: string;
    gameId: string;
    type: EventType;
    data: any;
    timestamp: number;
    playerId?: string;
    dmId?: string;
}

// 游戏数据接口
export interface IGameData {
    [key: string]: any;
    // 通用字段
    part?: number;
    roleList?: string[];
    storeManageListId?: string;
    // 自定义数据
    customData?: Record<string, any>;
}

// 游戏接口
export interface IGame {
    gameId: string;
    scriptId: string;
    status: GameStatus;
    players: Map<string, IPlayer>;
    dm?: IDM;
    data: IGameData;
    events: IGameEvent[];
    createdAt: number;
    updatedAt: number;
}

// 操作指令接口
export interface IGameAction {
    actionId: string;
    gameId: string;
    playerId: string;
    type: string;
    data: any;
    timestamp: number;
}

// 存储接口
export interface IStorage {
    getGame(gameId: string): Promise<IGame | null>;
    saveGame(game: IGame): Promise<void>;
    deleteGame(gameId: string): Promise<void>;
    getGamesByScript(scriptId: string): Promise<IGame[]>;
}

// 事件处理器接口
export interface IEventHandler {
    handle(event: IGameEvent, game: IGame): Promise<void>;
}

// 游戏配置接口
export interface IGameConfig {
    scriptId: string;
    name: string;
    maxPlayers: number;
    allowSpectators: boolean;
    permissions: {
        players: Permission[];
        dm: Permission[];
    };
}
